using System;
using System.Collections;

namespace WebApplication
{
	/// <summary>
	/// Summary description for StockMarketValues.
	/// </summary>
	[Serializable]
	public class StockMarketPositionCollection : ICollection
	{
		private ArrayList  _aStockMarketPositions;

		public StockMarketPosition this [int index]   // indexer declaration
		{ 
			get
			{
				return (StockMarketPosition) _aStockMarketPositions[index];
			}

			set
			{
				_aStockMarketPositions[index] = value;
			}
		}

		public StockMarketPosition this [string sLocation]   // indexer declaration
		{ 
			get
			{
				foreach (StockMarketPosition position in _aStockMarketPositions)
				{
					if (position.Location == sLocation)
						return position;
				}

				return (StockMarketPosition) _aStockMarketPositions[0];
			}

			set
			{
				int i = 0;

				foreach (StockMarketPosition position in _aStockMarketPositions)
				{
					if (position.Location == sLocation)
					{
						_aStockMarketPositions[i] = value;
						break;
					}

					i++;
				}
			}
		}


		public void CopyTo(Array a, int index)
		{
			_aStockMarketPositions.CopyTo(a, index);
		}
		public object SyncRoot
		{
			get{return this;}
		}
		public bool IsSynchronized
		{
			get{return false;}
		}

		public int Count
		{
			get
			{
				return _aStockMarketPositions.Count;
			}
		}

		public StockMarketPositionCollection ()
		{
			_aStockMarketPositions = new ArrayList ();
		}

		public void Add (System.Object position)
		{
			_aStockMarketPositions.Add (position);
		}

		public void Add (StockMarketPosition position)
		{
			_aStockMarketPositions.Add (position);
		}

		public void Remove (StockMarketPosition position)
		{
			_aStockMarketPositions.Remove (position);
		}

		// IEnumerable Interface Implementation:

		public IEnumerator GetEnumerator() // non-IEnumerable version
		{
			return _aStockMarketPositions.GetEnumerator ();
		}

		IEnumerator IEnumerable.GetEnumerator() // IEnumerable version
		{
			return _aStockMarketPositions.GetEnumerator ();
		}
	}

	[Serializable]
	public class StockMarketPosition
	{
		public enum eColor
		{
			White, Yellow, Brown, Red
		}


		private	string	_Location;
		private int		_Value;
		private eColor	_Color;
		private	int		_RunningOrder;

		private	string	_SoldOutLocation;
		private	string	_SoldLocation;
		private	string	_PayOutLocation;
		private	string	_HoldLocation;

		public StockMarketPosition()
		{
		}		

		public StockMarketPosition(string sLocation, int nValue, eColor color)
		{
			_Location		= sLocation;
			_Value			= nValue;
			_Color			= color;
			_RunningOrder	= 0;
		}


		public string Location
		{
			get	{ return _Location; }
			set { _Location = value; }
		}

		public int Value
		{
			get	{ return _Value; }
			set { _Value = value; }
		}

		public eColor Color
		{
			get	{ return _Color; }
			set { _Color = value; }
		}

		public int RunningOrder
		{
			get	{ return _RunningOrder; }
			set { _RunningOrder = value; }
		}


		public void	GetRowAndColumnParts(out char sRow, out int nCol)
		{
			string	sCell;

			sCell	= Location;
			sRow	= sCell[0];
            bool bReturn = int.TryParse(sCell.Remove(0, 1), out nCol);
		}

		public string SoldOutLocation
		{
			get	{ return _SoldOutLocation; }
			set { _SoldOutLocation = value; }
		}
		public string SoldLocation
		{
			get	{ return _SoldLocation; }
			set { _SoldLocation = value; }
		}
		public string PayOutLocation
		{
			get	{ return _PayOutLocation; }
			set { _PayOutLocation = value; }
		}
		public string HoldLocation
		{
			get	{ return _HoldLocation; }
			set { _HoldLocation = value; }
		}


		public int CertificateLimit
		{
			get
			{ 
				if (this.Color == eColor.White || this.Color == eColor.Yellow)	// can hold 6 is W or Y, 10 if B and 0 if R(closed)
					return 6;
				else if (this.Color == eColor.Brown)
					return 10;
				else
					return 0;
			}
		}

		public bool CountsAgainstCertificateLimit
		{
			get { return this.Color == eColor.White; }
		}

	}
}
